package net.sf.jsqlparser.statement.alter;

import java.util.List;

import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;
import net.sf.jsqlparser.statement.create.table.ColDataType;
import net.sf.jsqlparser.statement.select.PlainSelect;

/**
 * 添加或者删除单列
 * 
 * @author beifeng.xy
 * 
 */
public class AlterTable implements Statement {
	private String type = null;
	private Table table = null;
	private AlterColumn alterColumn = null;

	@Override
	public void accept(StatementVisitor statementVisitor) {
		// TODO Auto-generated method stub

	}

	public AlterTable() {

	}
	
	

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Table getTable() {
		return table;
	}

	public void setTable(Table table) {
		this.table = table;
	}

	
	public AlterColumn getAlterColumn() {
		return alterColumn;
	}

	public void setAlterColumn(AlterColumn alterColumn) {
		this.alterColumn = alterColumn;
		this.type = alterColumn.getType();
	}

	public String toString() {
		Column column = alterColumn.getColumn();
		String sql = "ALTER TABLE " + table;
		if (alterColumn instanceof AddColumn) {
			ColDataType colDataType = ((AddColumn)alterColumn).getColDataType();
			sql += " ADD " + column +" "+ colDataType;
			List<String> columnSpecs = ((AddColumn)alterColumn).getColumnSpecs();
			if (columnSpecs != null && columnSpecs.size() != 0) {
				sql += " ";
				sql += PlainSelect.getStringList(columnSpecs, false, false);
			}
		}else if (alterColumn instanceof DropColumn) {
			sql += " DROP COLUMN " + column;
		}
		return sql;

	}

}
